package com.wwy.arithmetic.suanfa;

/**
 * 最长公共前缀
 */
public class ZuiChangGongGong {
    /**
     * 示例 1：
     * <p>
     * 输入：strs = ["flower","flow","flight"]
     * 输出："fl"
     * 示例 2：
     * <p>
     * 输入：strs = ["dog","racecar","car"]
     * 输出：""
     * 解释：输入不存在公共前缀。
     */
    public static void main(String[] args) {

    }

    static String getQianZhui(String[] strs) {
        String res = "";
        if (strs == null || strs.length == 0) {
            return res;
        }
        if (strs.length == 1) {
            return strs[0];
        }
        String string = strs[0];
        for (int i = 0; i < string.length(); i++) {
            String substring = string.substring(0, i + 1);
            for (int j = 1; j < strs.length; j++) {
                if (strs[j].startsWith(substring)) {
                    continue;
                }else{
                    return res;
                }
            }
            res = substring;
        }
        return res;
    }
}
